﻿using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;

namespace Developer.Core.FrameWork.HelpFile
{
    /// <summary>
    /// 字典工具类
    /// </summary>
    public static class DictionaryUtil
    {
        /// <summary>
        /// 对象转换字典
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static IDictionary<string,object> ToDictionary(this object value)
        {
            IDictionary<string, object> dic = new Dictionary<string, object>();

            Type type = value.GetType();

            PropertyInfo[] propertyInfos = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);

            foreach (var p in propertyInfos)
            {
                dic.Add(p.Name, Convert.ToString(p.GetValue(value)));
            }

            return dic;
        }
    }
}
